package com.bobo.serviceorder.controller;

import com.bobo.serviceorder.dao.TbServiceOrderDao;
import com.bobo.serviceorder.entry.TbServiceOrder;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author bobo
 * @date 2021-04-09
 */
@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private TbServiceOrderDao tbServiceOrderDao;

    @GetMapping("/order")
    @GlobalTransactional(rollbackFor = Exception.class)
    public String order(){
        TbServiceOrder tbServiceOrder=new TbServiceOrder();
        tbServiceOrder.setId(1);
        tbServiceOrder.setName("订单1");
        tbServiceOrderDao.insert(tbServiceOrder);

        restTemplate.getForObject("http://service-account/account",String.class);
        restTemplate.getForObject("http://service-storage/storage",String.class);
        return "success";
    }
}
